package com.dpteam.dao.impl;

import com.dpteam.dao.CategoryDao;
import com.dpteam.model.Category;
import com.dpteam.util.Page;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/8
 * Time: 8:33
 */
@Repository
public class CategoryDaoImpl extends BaseDaoImpl<Category> implements CategoryDao {

    @Override
    public Category findByName(String name) {
        String hql = "from Category where typeName = ? ";
        return get(hql, name);
    }

    @Override
    public List<Category> findAll() {
        String hql = "from Category order by id ";
        return find(hql);
    }

    @Override
    public List<Category> findAllByPage(Page page) {
        String hql = "from Category order by id ";
        return find(hql, page);
    }

    @Override
    public void deleteById(int id) {
        Category category = get(Category.class, id);
        if (category != null) {
            delete(category);
        }
    }
}
